<?php
                class family_model extends CI_Model {
                    function __construct(){
                        parent::__construct();
                        $this->tableName = "family";
                    }
                    function insert($userid, $familitypeid, $name, $phone, $email, $address, $cityid, $provinceid, $zipcode){
                        $dt = array("userid" => $userid, 
                        "familitypeid" => $familitypeid, 
                        "name" => $name, 
                        "phone" => $phone, 
                        "email" => $email, 
                        "address" => $address, 
                        "cityid" => $cityid, 
                        "provinceid" => $provinceid, 
                        "zipcode" => $zipcode);
                        $this->db->insert($this->tableName, $dt);
                        return $this->db->insert_id();
                    }
                    
                    function update($familyid, $dt, $where=""){
                        $this->db->where("familyid", $familyid);
                        if($where != "")$this->db->where($where);
                        $this->db->update($this->tableName, $dt);
                    }
                    
                    function delete($familyid,  $where = ""){
                        $this->db->where("familyid", $familyid);
                        if($where != "")$this->db->where($where);
                        $this->db->delete($this->tableName);
                    }
                    
                    function getById($familyid,  $where=""){
                        $this->db->where("familyid", $familyid);
                        if($where != "")$this->db->where($where);
                        return $this->db->get($this->tableName)->row();
                    }
                    
                    function getAll($startpage="0", $perpage="10", $where = "", $orderby=""){
                        if($where != "")$this->db->where($where);
                        $this->db->limit($perpage, $startpage);
                        if($orderby != "")$this->db->order_by($orderby);
                        return $this->db->get($this->tableName)->result();
                    }
                    
                    function getAllCount($where = ""){
                        $this->db->select("COUNT(*) JUMLAH");
                        $this->db->from($this->tableName);
                        if($where != "")$this->db->where($where);
                        return $this->db->get()->row()->JUMLAH;
                    }
                }
                ?>